/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.pdx.cs.guavadata.subclass;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import org.apache.commons.lang3.StringUtils;

/**
 *
 * @author VuTran
 */
public class GSeedFrame {

    public UUID g;
    public String form;
    public List<String> controls;


    public GSeedFrame() {
        controls = new ArrayList<String>();
    }

    public GSeedFrame(UUID id, String form) {
        this();
        this.g = id;
        this.form = form;
    }

    public List<String> toList() {
        List<String> ls = new ArrayList<String>();
        ls.add(form);;
        for (String s : controls)
            ls.add(s);
        return ls;
    }

    @Override
    public String toString() {
        return g.toString() + ":" + form + ":" + StringUtils.join(controls.toArray(), "/");
    }

    public static GSeedFrame fromString(String s) {
        List<String> ls = new ArrayList<String>(Arrays.asList(s.split(":")));

        // First element is guid, second is form
        GSeedFrame gsfTemp = new GSeedFrame(UUID.fromString(ls.get(0)), ls.get(1));
        
        // third element is list of controls concatenated with /
        gsfTemp.controls = new ArrayList<String>(Arrays.asList(ls.get(2).split("/")));

        return gsfTemp;
    }
}
